package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityGoodsCarsBinding;
import com.sgb.kjwl.view.ui.fragment.transport.MapCarsFragment;
import com.sgb.kjwl.view.ui.fragment.transport.MapGoodsFragment;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;

import java.util.ArrayList;

public class MapGoodsAndCarsActivity extends AppActivity {

    private ActivityGoodsCarsBinding binding;
    private ArrayList<Fragment> mFragments;
    private String[ ] titles = {"可视找货","可视找车"};
    private FragPagerAdapter pagerAdapter;

    public static void start(Context context,int index){
        Intent intent = new Intent(context,MapGoodsAndCarsActivity.class);
        intent.putExtra("index", index);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_goods_cars);
        binding.ivBack.setOnClickListener(view -> finish());
        binding.rightView.setVisibility(View.GONE);
    }

    @Override
    protected void init() {
        mFragments = new ArrayList<>();
        mFragments.add(MapGoodsFragment.newInstance());
        mFragments.add(MapCarsFragment.newInstance(true));
        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(2);
       // binding.tablayout.setViewPager(binding.viewpager, titles);
        int index = getIntent().getIntExtra("index",0);
        binding.viewpager.setCurrentItem(index);
    }
}
